# 1. 注册实例页面,3个表单的注册操作
import os
import time
from selenium.webdriver.common.by import By
from selenium import webdriver
# 进入主文档
driver = webdriver.Chrome()
driver.maximize_window()
# 获取文档的绝对路径
file = "file:///"+ os.path.abspath("html")+"/注册实例.html"
# 打开文档
driver.get(file)
# 主文档注册
# 输入注册信息
driver.find_element(By.ID, "user").send_keys('diyige')
driver.find_element(By.ID, "password").send_keys('123456')
driver.find_element(By.ID, "tel").send_keys('18812345678')
driver.find_element(By.ID, "email").send_keys('diyi@diyi.com')
# 点击注册按钮
driver.find_element(By.CSS_SELECTOR, "button[title='加入会员']").click()

# iframe切换注册A
frame1 = driver.find_element(By.ID, "idframe1")
driver.switch_to.frame(frame1)
# 注册A输入信息
driver.find_element(By.ID, "userA").send_keys('dierge')
driver.find_element(By.ID, "passwordA").send_keys('123456')
driver.find_element(By.ID, "telA").send_keys('18812345678')
driver.find_element(By.ID, "emailA").send_keys('dier@dier.com')
time.sleep(3)
# 点击注册按钮
driver.find_element(By.CSS_SELECTOR, "button[title='加入会员A']").click()
# 切换到主页面
driver.switch_to.default_content()
# iframe切换注册B
frame2 = driver.find_element(By.NAME, "myframe2")
driver.switch_to.frame(frame2)
# 注册B输入信息
driver.find_element(By.ID, "userB").send_keys('disange')
driver.find_element(By.ID, "passwordB").send_keys('123456')
driver.find_element(By.ID, "telB").send_keys('18812345678')
driver.find_element(By.ID, "emailB").send_keys('disan@disan.com')
# 点击注册按钮
driver.find_element(By.CSS_SELECTOR, "button[title='加入会员B']").click()

time.sleep(3)
driver.quit()